import { http } from '@/utils/axios/http'
import { AccountDTO, SaveUserDTO, SysUserRole, UserFindDTO } from './userType'
const api = http.create({ baseURL: process.env.VITE_APP_CIMS_API })

/**
 * 查询用户列表
 */
const findUserList = (params: UserFindDTO) => {
  return api.post('/api/sysUser/findUserList', params)
}

/**
 * 保存用户
 */
const saveUser = (params: SaveUserDTO) => {
  return api.post('/api/sysUser/saveUser', params)
}

/**
 * 删除用户
 */
const deleteUser = (userId: string) => {
  return api.post('/api/sysUser/deleteUser', { userId })
}

/**
 * 重置密码
 */
const resetPassword = (params: AccountDTO) => {
  return api.post('/api/sysAccount/resetPassword', params)
}

/**
 * 修改密码
 */
const updatePassword = (params: AccountDTO) => {
  return api.post('/api/sysAccount/updatePassword', params)
}

/**
 * 查询用户角色列表
 */
const findUserRoleList = (userId: string) => {
  return api.get('/api/sysUser/findUserRoleList', { params: { userId } })
}

/**
 * 保存用户角色
 */
const addUserRole = (params: SysUserRole) => {
  return api.post('/api/sysUser/addUserRole', params)
}

export const userApi = {
  findUserList,
  saveUser,
  deleteUser,
  resetPassword,
  findUserRoleList,
  addUserRole,
  updatePassword
}
